#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
    int x=0;char ch=getchar();
    while(!isdigit(ch)) ch=getchar();
    while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    return x;
}
const int N=5e5+10;
int n,q,p,a[N];
ll ans,res[N];
ll S(int x) {return 1ll*x*(x+1)>>1;}
void solve(int x)
{
    ll ans=0;
    for(int i=0;i<p;i++)
        ans+=res[1ll*i*x%p];
    printf("%lld\n",ans);
}
int main()
{
    freopen("string.in","r",stdin);
    freopen("string.out","w",stdout);
    n=read(),q=read(),p=read();
    for(int i=1;i<=n;i++) a[i]=read();
    for(int i=1,t=1;i<=n;i=t)
    {
        while(t<=n&&a[i]==a[t]) ++t;
        res[a[i]]+=S(t-i);
    }
    int op,x;
    while(q--)
    {
        ans=0;
        op=read(),x=read();
        if(op==1)
        {
            for(int i=0;i<p;i++)
                for(int j=1;j<=n;j++)
                    for(int k=j;k<=n;k++)
                    {
                        bool flag=1;
                        for(int h=j;h<=k;h++)
                        {
                            if((x*a[h]+i)%p!=a[k-h+j]) {flag=0;break;}
                        }
                        ans+=flag;
                    }
        }
        else
        {
            for(int i=0;i<p;i++)
                for(int j=1;j<=n;j++)
                    for(int k=j;k<=n;k++)
                    {
                        bool flag=1;
                        for(int h=j;h<=k;h++)
                        {
                            if((i*a[h]+x)%p!=a[k-h+j]) {flag=0;break;}
                        }
                        ans+=flag;
                    }
        }
        printf("%lld\n",ans);
    }
    return 0;
}